package cn.zz.veggie.model.query;

import java.util.Collection;
import java.util.Objects;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.zz.comm.core.types.query.PageQuery;
import cn.zz.veggie.model.domain.Admin;
import lombok.Getter;
import lombok.Setter;

/**
 * 管理员表(Admin)查询器
 *
 * @author zhongq
 * @since 2024-05-13 20:42:21
 */
@Getter
@Setter
public class AdminQuery {
	private Integer id;
	private Collection<Integer> ids;
	private String likeMobile;
	private String likeUsername;
	private Long createdAtStart;
	private Long createdAtEnd;

	public LambdaQueryWrapper<Admin> toQueryWrapper() {
		final LambdaQueryWrapper<Admin> queryWrapper = Wrappers.lambdaQuery();

		queryWrapper.eq(Objects.nonNull(id), Admin::getId, id);
		queryWrapper.in(Objects.nonNull(ids), Admin::getId, ids);
		queryWrapper.ge(Objects.nonNull(createdAtStart), Admin::getCreateAt, createdAtStart);
		queryWrapper.lt(Objects.nonNull(createdAtEnd), Admin::getCreateAt, createdAtEnd);
		queryWrapper.like(Objects.nonNull(likeMobile), Admin::getMobile, likeMobile);
		queryWrapper.like(Objects.nonNull(likeUsername), Admin::getUsername, likeUsername);
		return queryWrapper;
	}

	// todo
	private void inject() {

	}

	public Page<Admin> toPage(PageQuery p) {
		Page<Admin> page = new Page<>(p.getCurrent(), p.getSize());
		// TODO 2024/7/13 10:12 order by
		page.setOptimizeCountSql(p.isOptimizeCountSql());
		page.setSearchCount(p.isSearchCount());
		page.setOptimizeJoinOfCountSql(p.isOptimizeJoinOfCountSql());
		page.setCountId(p.getCountId());
		return page;
	}

}